package com.weibo.zhifa.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.weibo.common.CommonUtil;
import com.weibo.common.ValidateUserServlet;
import com.weibo.user.User;
import com.weibo.zhifa.ZhiFa;
import com.weibo.zhifa.service.ZhifaService;
import com.weibo.zhifa.service.imp.ZhifaServiceImp;

public class TaskManagerServlet extends ValidateUserServlet {
	private static Logger logger = Logger.getLogger(TaskManagerServlet.class);

	@Override
	public void doService(HttpServletRequest request,
			HttpServletResponse response) {
		logger.info("直发TaskManagerServlet被请求了！");
		request.setAttribute("currentmenu", "任务管理");
		ZhifaService zhifaService=new ZhifaServiceImp();
		String currentPage = request.getParameter("currentPage");
		if (currentPage == null || "".equals(currentPage)) {
			currentPage = "0";
		}
		User user = CommonUtil.getLoginUser(request);
		List<ZhiFa> zhifalist=zhifaService.getZhifaList(Integer.parseInt(currentPage));
		int totalPageNum=CommonUtil.getTotalPageNum(zhifaService.getTaskTotalSize(user.getUser_id()));
		request.setAttribute("currentPage", currentPage);
		request.setAttribute("totalPageNum", totalPageNum);
		request.setAttribute("zhifalist", zhifalist);
		try {
			request.getRequestDispatcher("/WEB-INF/task/Task_manager.jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
